package pub.guoxin.oops.manager.handler;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

import static pub.guoxin.oops.manager.handler.AlarmFieldNameConstants.*;

/**
 * Create by guoxin on 2018/3/30
 */
@Configuration
public class AlarmInfoHandlerConfiguration {

    @Resource(name = COMMUNICATION_BATTERY + AlarmInfoHandler)
    private AbstractAlarmInfoHandler communicationBatteryAlarmInfoHandler;

    @Resource(name = DEVICE_BATTERY + AlarmInfoHandler)
    private AbstractAlarmInfoHandler deviceBatteryAlarmInfoHandler;

    @Resource(name = NORM_MOMENT_FLOW + AlarmInfoHandler)
    private AbstractAlarmInfoHandler normMomentFlowAlarmInfoHandler;

    @Resource(name = WORK_MOMENT_FLOW + AlarmInfoHandler)
    private AbstractAlarmInfoHandler workMomentFlowAlarmInfoHandler;

    @Resource(name = WORK_PRESSURE + AlarmInfoHandler)
    private AbstractAlarmInfoHandler workPressureAlarmInfoHandler;

    @Resource(name = WORK_TEMPERATURE + AlarmInfoHandler)
    private AbstractAlarmInfoHandler workTemperatureAlarmInfoHandler;

    @Bean
    public AbstractAlarmInfoHandler alarmInfoHandlerChain() {
        communicationBatteryAlarmInfoHandler.setSuccessor(deviceBatteryAlarmInfoHandler);
        deviceBatteryAlarmInfoHandler.setSuccessor(normMomentFlowAlarmInfoHandler);
        normMomentFlowAlarmInfoHandler.setSuccessor(workMomentFlowAlarmInfoHandler);
        workMomentFlowAlarmInfoHandler.setSuccessor(workPressureAlarmInfoHandler);
        workPressureAlarmInfoHandler.setSuccessor(workTemperatureAlarmInfoHandler);
        AbstractAlarmInfoHandler alarmInfoHandlerChain = communicationBatteryAlarmInfoHandler;
        return alarmInfoHandlerChain;
    }

}
